import java.awt.*;

class Radiation extends GameElement {
    public Radiation(float x, float y, int size, Color color, float effect, float duration) {
        super(x, y, size, color, effect, duration);

    }

    @Override
    public boolean update() {
        super.update();

        if (Math.random() < 0.05) {
            floatDirection = (float) (Math.random() * Math.PI * 2);
        }

        Embryo embryo = GameState.getInstance().getEmbryo();
        float dx = embryo.getX() - x;
        float dy = embryo.getY() - y;
        float dist = (float) Math.sqrt(dx * dx + dy * dy);

        if (dist > 0) {
            float seekForce = 0.5f; // 50%速度向胚胎移动
            x += (dx / dist) * floatSpeed * seekForce;
            y += (dy / dist) * floatSpeed * seekForce;
        }

        return age < duration;
    }


    @Override
    public void draw(Graphics2D g) {
        // 绘制辐射光环效果
        float alpha = 1 - age / duration;
        g.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), (int) (alpha * 150 + 50)));

        // 绘制多个同心圆模拟辐射效果
        for (int i = 0; i < 3; i++) {
            int currentSize = size + i * 10;
            g.drawOval((int) x - currentSize / 2, (int) y - currentSize / 2, currentSize, currentSize);
        }

        // 中心点
        g.fillOval((int) x - size / 2, (int) y - size / 2, size, size);
    }
}
